package acm.蓝桥杯;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class D食堂2 {
    static int maxN = 100;
    public static void main(String[] args) {
        Reader2 sc = new Reader2();
        int t = sc.nextInt();
        while (t-- > 0) {
            int a2 = sc.nextInt();
            int a3 = sc.nextInt();
            int a4 = sc.nextInt();
            int b4 = sc.nextInt();
            int b6 = sc.nextInt();
            int res = 0;
            int total=b4*4+b6*6;
            out:
            for (int i = 0; i <= a2; i++) {
                for (int j = 0; j <= a3; j++) {
                    for (int k = 0; k <= a4; k++) {
                        int cur=i*2+j*3+k*4;
                        if (cur == total) {
                            res =cur;
                            break out;
                        } else if (total > cur) {
                            res = Math.max(res, cur);
                        }
                    }
                }
            }
            System.out.println(res);
        }
    }
    static
    class Reader2 {
        private StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        public int nextInt(){
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
        public double nextDouble(){
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return in.nval;
        }
    }

}
